package com.lineng.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {

	public static String DATE_FORMAT = "yyyy-MM-dd";
	public static String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

	/** 返回当前字符串日期 yyyy-MM-dd **/
	public static String getCurrentDate() {
		Date now = new Date();
		SimpleDateFormat dateFmt = new SimpleDateFormat(DATE_FORMAT);
		return dateFmt.format(now);
	}

	/** 返回当前字符串日期 yyyy-MM-dd HH:mm:ss **/
	public static String getCurrentDateTime() {
		Date now = new Date();
		SimpleDateFormat dateFmt = new SimpleDateFormat(DATE_TIME_FORMAT);
		return dateFmt.format(now);
	}

	/** 获取当前日期的后一天 **/
	public static Date getCurrentDateNextDay() {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		calendar.add(Calendar.DAY_OF_MONTH, +1); // 今天的时间加一天
		return calendar.getTime();
	}

	public static Date getNextDay(Date date) {
		long date_3_hm = date.getTime() + 1000 * 60 * 60 * 24;
		Date date_3_hm_date = new Date(date_3_hm);
		return date_3_hm_date;
	}

	/** 判断两个日期是不是同一天 **/
	public static boolean isSameDate(Date date1, Date date2) {
		String str1 = formatDateToString(date1, DATE_FORMAT);
		String str2 = formatDateToString(date2, DATE_FORMAT);
		if (str1.equals(str2)) {
			return true;
		}
		return false;
	}

	// 将日期转成特定格式的字符串
	public static String formatDateToString(Date date, String formatStr) {
		try {
			SimpleDateFormat dateFmt = new SimpleDateFormat(formatStr);
			if (date != null) {
				return dateFmt.format(date);
			} else {
				return "";
			}
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
	}

}
